import {Component, OnInit, ViewChild} from '@angular/core';
import {RechargeModalComponent} from "../recharge-modal/recharge-modal.component";
import {BalanceService} from "../../service/balance.service";
import {PageParam} from "../../model/params.model";
import {USER} from "../../service/user.service";
import {UserModel} from "../../model/user.model";

@Component({
  selector: 'app-my-balance-view',
  templateUrl: './my-balance-view.component.html',
  styleUrls: ['./my-balance-view.component.scss']
})
export class MyBalanceViewComponent implements OnInit {
  @ViewChild(RechargeModalComponent) public rechargeModal:any;
  pageParam:PageParam;
  pagination = {
    page: 1,
    totalPage: 1
  }
  bills:any;
  user:UserModel;

  constructor(private balanceService:BalanceService, private USER:USER) {
    this.user = this.USER.get();
  }

  ngOnInit() {
    this.USER.refreshUser.subscribe(v=> {
      console.log("USER.refresh");
      this.user = this.USER.get();
    })
    this.queryList()
  }

  queryList() {
    this.balanceService.getList(resp=> {
      this.pagination.totalPage = resp.totalPages;
      this.bills = resp.content;
      console.log(this.bills)
    }, this.pageParam)
  }

  goRechargeModal() {
    this.rechargeModal.showModal();
  }
}
